/*
 * CPCB.cpp
 *
 *  Created on: 13-05-2013
 *      Author: Sucharinho
 */

#include "CPCB.h"

void CPCB::SetFunction(PINFUN::EPort0 pinFunction) {
	unsigned char pin = ((pinFunction & 0xFC) >> 1);
	unsigned char function = pinFunction & 0x03;
	if (pin < 32)
		PINSEL0 = (PINSEL0 & ~(3 << pin)) | (function << pin);
	else
		PINSEL1 = (PINSEL1 & ~(3 << (pin - 32))) | (function << (pin - 32));
}

void CPCB::SetFunction(PINFUN::EPort1 pinFunction) {
	unsigned char pin = ((pinFunction & 0xFC) >> 1);
	unsigned char function = pinFunction & 0x03;
	if (pin < 32)
		PINSEL2 = (PINSEL2 & ~(3 << pin)) | (function << pin);
	else
		PINSEL3 = (PINSEL3 & ~(3 << (pin - 32))) | (function << (pin - 32));
}

void CPCB::SetFunction(PINFUN::EPort2 pinFunction) {
	unsigned char pin = ((pinFunction & 0xFC) >> 1);
	unsigned char function = pinFunction & 0x03;
	PINSEL4 = (PINSEL4 & ~(3 << pin)) | (function << pin);

}

void CPCB::SetFunction(PINFUN::EPort3 pinFunction) {
	unsigned char pin = ((pinFunction & 0xFC) >> 1);
	unsigned char function = pinFunction & 0x03;
	PINSEL7 = (PINSEL7 & ~(3 << (pin - 32))) | (function << (pin - 32));
}

void CPCB::SetFunction(PINFUN::EPort4 pinFunction) {
	unsigned char pin = ((pinFunction & 0xFC) >> 1);
	unsigned char function = pinFunction & 0x03;
	PINSEL9 = (PINSEL9 & ~(3 << (pin - 32))) | (function << (pin - 32));
}
